from selenium import webdriver
from time import sleep

if __name__ == '__main__':
    brower = webdriver.Chrome(executable_path=r"E:\pytho-tool\webdriver\chromedriver.exe")
    brower.get("https://www.baidu.com/")
    sleep(2)
    brower.refresh()
    brower.set_window_size(1400, 800)

    search_text = brower.find_element_by_id("kw")
    search_text.send_keys("stanfurd is handsome boy")
    search_button = brower.find_element_by_id("su")
    search_button.click()
    sleep(3)

    js_height = "return document.body.clientHeight"
    height = brower.execute_script(js_height)
    print("execute js script is %s, the page height is %d " % (js_height, height))
    brower.save_screenshot("E:\pytho-tool\webphoto\stanford.png")

    print("start get the html width and height")
    eles = brower.find_elements_by_xpath("//html")
    locs = []
    width = 1920
    height = 1080
    if len(eles) > 0:
        width = int(eles[0].size['width'])+500
        height = int(eles[0].size['height'])+500
    print("the html width: %d and height: %d" % (width, height))
    brower.set_window_size(width, height)
    brower.save_screenshot("E:\pytho-tool\webphoto\long_photo.png")

    # element = brower.find_element_by_link_text("新闻")
    # element.click()
    #brower.quit()
